package faq.entity;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class MyBatisUtil {
	private static SqlSessionFactory factory;
	//静态块
	static{
		//加载配置文件
		InputStream in;
		try {
			in=Resources.getResourceAsStream("mybatis-config.xml");
			//创建session工厂
			factory=new SqlSessionFactoryBuilder().build(in);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	//创建session
	public static SqlSession openSession(){
		return factory.openSession();
	}
}
